<?php
namespace app\admin\model;
use think\Model;
use app\admin\model\Areas;
use app\admin\model\BaseModel;
class Pops extends BaseModel
{
	
	/*获取接入点的名称*/
	public static function getNameLabel($pop_id){
		$name = db('pops')->where(['id'=>$pop_id])->value('name');
		return empty($name) ? '--' : $name;
	}
	/*获取详细地址*/
	public function getAddrAttr($value,$data){

	}	
	/*获取国家*/
	public function getCountryAttr($value){
		return Areas::getAreaName($value);
	}
	/*获取国家*/
	public function getCityAttr($value){
		return Areas::getAreaName($value);
	}
	/*获取pop存在的国家地区*/
	public static function getPOPCountrys(){
		$countryIds = self::where(['status'=>1])->column('id,area_id','area_id');
		$countrys = [];
		if($countryIds){
			$areas = new Areas;
			$countrys = $areas->where('id',"in",array_keys($countryIds))->field('id,name'.self::prexLang().',icon')->order('name'.self::prexLang().' asc,sort asc')->select();
		}
		return $countrys;
	}
	/*获取pop存在的国家地区*/
	public static function getPOPCountryCitys(){
		$countryIds = self::where(['status'=>1])->column('id,area_id','area_id');
		$countrys = [];
		if($countryIds){
			$areas = new Areas;
			$countrys = $areas->alias('a')
			->join('areas b',"b.pid=a.id")
			->where('a.id',"in",array_keys($countryIds))->field('a.id,a.name'.self::prexLang().' as name,a.icon,b.name'.self::prexLang().' as city,b.id as city_id')->order('a.name'.self::prexLang().' asc,a.sort asc')->select();
		}
		return $countrys; 
	}
	/*获取pop存在的国家地区城市*/
	public static function getPOPCitys($country_id){
		$cityIds = self::where(['status'=>1,'area_id'=>$country_id])->column('id,city_id','city_id');
		$citys = [];
		if($cityIds){
			$areas = new Areas;
			$citys = $areas->where('id',"in",array_keys($cityIds))->where(['pid'=>$country_id])->field('id,lng,lat,name'.self::prexLang().' as name,icon')->order('name'.self::prexLang().' asc,sort asc')->select();
		}
		return $citys;
	}
	/*获取位置id*/
	public static function getLocationId($item_id){
		return self::where(['id'=>$item_id])->value('locationId');
	}
}	